<?php
/**
 * Created by PhpStorm.
 * User: wdxi
 * Date: 2017/3/7
 * Time: 10:56
 */

namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Order extends Model
{
    use SoftDeletes;//开启软删除

    protected $connection = 'mysql_thor';

    protected $dates=['deleted_at'];
    protected $guarded=[];//不可注入的数据为空

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function channel()
    {
        return $this->belongsTo(Channel::class)->withTrashed();
    }

    public function auditor()
    {
        return $this->belongsTo(AdminUser::class)->withTrashed();
    }
    public function admin()
    {
        return $this->belongsTo(AdminUser::class, 'admin_id')->withTrashed();
    }

    public function financial()
    {
        return $this->belongsTo(AdminUser::class, 'financial_id')->withTrashed();
    }

    public function collector()
    {
        return $this->belongsTo(AdminUser::class,'collector_id', 'id')->withTrashed();
    }
    public function product(){
        return $this->belongsTo(Product::class, 'product_id', 'id')->withTrashed();
    }

    public function extendoffline(){
        return $this->hasMany(ExtendOffline::class);
    }

    public function orderoffline(){
        return $this->hasMany(OrderOffline::class);
    }

    public function bairongDecision(){
        return $this->hasOne(BairongScore::class, 'out_trade_no', 'out_trade_no');
    }

    public function helpTables(){
        return $this->hasOne(HelpTable::class, 'out_trade_no', 'out_trade_no');
    }

    public function tradeInfo(){
        return $this->hasMany(TradeInfo::class, 'order_id', 'id');
    }

    public function divideOrders(){
        return $this->hasMany(DivideOrder::class, 'order_id', 'id');
    }
}
